package com.bra.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import com.bra.R;
import com.bra.bean.HomeMessageBean;
import com.bra.view.ImagerLoaderHelper;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
 * 首页 左右滑动信息adapter
 * @author lenovo
 *
 */
public class Home_hsc_adapter extends BaseAdapter {
	private Context context;
	private List<HomeMessageBean>homepages=new ArrayList<HomeMessageBean>();
	private LayoutInflater mInflater;
	private ImageLoader imageLoader;
	private ImagerLoaderHelper imageLoaderHelper;

	public Home_hsc_adapter(Context context,List<HomeMessageBean> homepages) {
		this.context = context;
		this.homepages = homepages;
		imageLoader = ImageLoader.getInstance();
		imageLoaderHelper = ImagerLoaderHelper.getInstance();
		mInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return homepages.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return homepages.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.home_hsc_type_item, null);			
			holder.home_hsc_type_name = (TextView) convertView.findViewById(R.id.home_hsc_type_name);	
			holder.home_hsc_type_iv=(ImageView) convertView.findViewById(R.id.home_hsc_type_iv);	
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.home_hsc_type_name.setText(homepages.get(position).getTitle());	
		imageLoader.displayImage(homepages.get(position).getImageSrc(), holder.home_hsc_type_iv,imageLoaderHelper.getOptions());				
		return convertView;
	}

	public class ViewHolder {		
		private TextView home_hsc_type_name;	
		private ImageView home_hsc_type_iv;
	}

}
